import Vue from 'vue'
import Router from 'vue-router'
import BasicSetting from '@/store/BasicSetting'
import Home from '@/components/home/'
import Login from '@/components/common/Login'
import ManageHome from '@/components/back/'
import ManageHomev1 from '@/components/back/Indexv1'

Vue.use(Router)

const constantRouterMap = [
  {
    path: '/',
    redirect: '/login'
  }, {
    path: '/login',
    component: Login,
    meta: {
      title: '登录',
      requireAuth: false
    }
  }, {
    path: '/home',
    component: Home,
    meta: {
      title: '首页',
      requireAuth: false
    }
  }, {
    path: '/back',
    component: BasicSetting.menuStyle === 1 ? ManageHome : ManageHomev1,
    meta: {
      title: '管理台',
      requireAuth: true
    }
  }
]

export default new Router({
  routes: constantRouterMap,
  mode: 'hash' // 路由访问模式 'hash' : 'history'
})

export const asyncRouterMap = [
  {
    path: '/back',
    component: BasicSetting.menuStyle === 1 ? ManageHome : ManageHomev1,
    meta: {
      title: '管理台',
      requireAuth: true
    },
    children: [
      {
        path: '/index',
        name: 'index',
        title: '首页',
        component: () => import('@/components/back/common/Home')
      }, {
        path: '/system',
        name: 'system',
        title: '系统管理',
        component: () => import('@/components/back/system/'),
        children: [
          {
            path: '/system/userManager',
            name: 'userManager',
            title: '用户管理',
            component: () => import('@/components/back/system/UserManager')
          }, {
            path: '/system/roleManager',
            name: 'RoleManager',
            title: '角色管理',
            // component: () => import('@/components/back/system/RoleManager')
            // component: resolve => (require(['@/components/back/system/RoleManager'], resolve))
            component: (resolve) => require(['@/components/back/system/RoleManager'], resolve)
          }
        ]
      }, {
        path: '/charts',
        name: 'charts',
        title: '图表展示',
        component: () => import('@/components/back/charts/'),
        children: [
          {
            path: '/charts/chart',
            name: 'chart',
            title: '统计图展示',
            component: (resolve) => require(['@/components/back/charts/chart/Index'], resolve)
          }, {
            path: '/charts/map',
            name: 'map',
            title: '地图展示',
            // component: (resolve) => require(['@/components/back/charts/map/Index'], resolve)
            component: (resolve) => require(['@/components/back/charts/fengmap/Index'], resolve)
          }
        ]
      }
    ]
  }
]
